import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-11-11
 * Time: 20:58
 */
public class Test1 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();//T组测试用例
        int[] diff = new int[T];//差值
        for(int j = 0; j < T; j++) {
            int n = in.nextInt();//比赛数
            int k = in.nextInt();// >3连胜奖励的星数
            in.nextLine();
            String str = in.nextLine();
            int winC = 0;//连胜次数
            for(int i = 0; i < n; i++) {
                char ch = str.charAt(i);
                if(ch == 'W') {
                    winC++;
                    if(winC >= 3) {
                        diff[j] += k;
                    }else {
                        diff[j]++;
                    }
                }else {
                    diff[j]--;
                    winC = 0;
                }
            }
        }
        for(int x : diff) {
            System.out.println(x);
        }
    }
}
